#include "Entity.h"
#include "Message.h"
#include "PostOffice.h"
#include "World.h"
#include "zone.h"

Entity::Entity()
{
    node__ = 0;
    smgr__ = World::getSceneManager();
    currentZone__ = -1;
}

ISceneNode * Entity::getNode()
{
    return node__ ;
}

Entity::~Entity()
{
	if (node__ != 0)
		node__->remove();
}

irr::core::string<c8>& Entity::getType()
{
	return type__;
}

irr::core::string<c8>& Entity::getGroup()
{
	return group__;
}

void Entity::setGroup(const irr::core::string<c8>& group)
{
	if (group__ != "")
		PostOffice::UnregisterGroup(this, group__.c_str());
	
	if (group != "")
		PostOffice::RegisterGroup(this, group.c_str());

	group__ = group;
}

void Entity::setType(const irr::core::string<c8>& type)
{
	type__ = type;
}

void Entity::showBB(bool enabled)
{
	if (!node__)
		return;
	
	if (enabled)
		node__->setDebugDataVisible(EDS_BBOX);
	else
		node__->setDebugDataVisible(EDS_OFF);
}

void Entity::sendMessage(Entity* receiver, const std::string& message, const std::string& extra)
{
     PostOffice::DispatchMessage(this,receiver, message,extra);
}

void Entity::sendMessage(Entity* receiver, const std::string& message, const std::string& extra, irr::core::vector3df about)
{
     PostOffice::DispatchMessage(this,receiver, message,extra,about);
}

void Entity::sendMessage(Entity* receiver, const std::string& message)
{
	PostOffice::DispatchMessage(this,receiver, message);
}

void Entity::sendMessage(const std::string& group, const std::string& message, const std::string& extra, irr::core::vector3df about)
{
	PostOffice::DispatchMessage(this,group, message,extra,about);
}

void Entity::sendMessage(const std::string& group, const std::string& message)
{
	PostOffice::DispatchMessage(this,group, message);
}

bool Entity::checkMail()
{
	return mailbox__.size() > 0;
}

Message Entity::readMessage()
{
	if (checkMail())
	{
		Message m = *mailbox__.begin();
		mailbox__.pop_front();
		return m;
	}
	else
		return Message("");
}

void Entity::setLastZone(int z)
{
	lastZone__ = z;
}

void Entity::setZone(int z)
{
	currentZone__ = z;
}

int Entity::getLastZone()
{
	return lastZone__;
}

int Entity::getZone()
{
	return currentZone__;
}

